<?php
require 'lib/init.php';
//http://www.blog.com/art.php?id=6 union select 1,2,3,username,password,6,7,8 from user
$_GET['id']=$_GET['id']+0;//防止sql注入

if(!empty($_POST)){
    $flag=true;
    $comment=[];
    $_POST['comment'] = htmlspecialchars($_POST['comment']);
    empty(trim($_POST['username']))?$flag=false:$comment['nick']=$_POST['username'];
    empty(trim($_POST['email']))?$flag=false:$comment['email']=$_POST['email'];
    empty(trim($_POST['comment']))?$flag=false:$comment['content']=$_POST['comment'];
    $comment['pubtime']=time();
    $comment['art_id']=$_GET['id'];
    $comment['ip']=sprintf('%u',ip2long(getIp()));
    if($flag===true){
        mExec('comment',$comment);
        mQuery("update article set comm=comm+1 where art_id=$_GET[id]");
    }else{
        echo '<script>alert("好好留言");history.go(-1);</script>';
    }
}

$comms=mGetAll("select * from comment where art_id=$_GET[id] order by comment_id desc;");

$cats = mGetAll('select * from cat');
$art = mGetRow("select article.*,cat.cat_name from article left join cat on article.cat_id=cat.cat_id where art_id=$_GET[id];");
require 'view/front/art.html';


